package diseaseandcureadministration;

import java.util.ArrayList;

import diseaseandcureadministration.disease.Disease;
import diseaseandcureadministration.symptom.Symptom;

public class Patient 
{
	private String _name;
	private int _health;
	private ArrayList<Symptom> _symptoms;
	
	public Patient(String name)
	{
		_name = name;
		_health = 100;
		_symptoms = new ArrayList<Symptom>();
	}
	
	public Patient(String name, ArrayList<Symptom> symptoms)
	{
		this(name);

		for(Symptom symptom: symptoms)
		{
			addSymptom(symptom);
		}
	}
	
	public Patient(String name, Disease disease)
	{
		this(name, disease.getSymptoms());
	}
	
	public String getName()
	{
		return _name;
	}
	
	public int getHealth()
	{
		return _health;
	}
	
	public void heal(int healFactor)
	{
		_health += healFactor;
		
		if(_health >= 100)
		{
			_symptoms.clear();
			_health = 100;
		}
	}
	
	public void infect(Disease disease)
	{
		for(Symptom symptom: disease.getSymptoms())
		{
			addSymptom(symptom);
		}
	}
	
	public void addSymptom(Symptom symptom)
	{
		applySymptomDamageFactor(symptom);
		_symptoms.add(symptom);
	}
	
	private void applySymptomDamageFactor(Symptom symptom)
	{
		_health *= symptom.getSeverity().damageFactor();
	}
	
	public ArrayList<Symptom> getSymptoms()
	{
		ArrayList<Symptom> copyOfSymptoms = new ArrayList<Symptom>();
		
		for(Symptom symptom: _symptoms)
		{
			copyOfSymptoms.add(symptom);
		}
		
		return copyOfSymptoms;
	}
	
	@Override
	public String toString()
	{
		String patientAsString = _name + ", " + _health + ", " + _symptoms;
		return patientAsString;
	}
}
